/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package multiThreadedressbook;

import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Antoine
 */
public class FormModify extends JFrame{
    protected JButton modify = new JButton("Modify");
protected JTextField name = new JTextField(20);
protected JTextField firstname = new JTextField(20);
protected JTextField homeAddress = new JTextField(20);
protected JTextField compagnyAddress = new JTextField(20);
protected JTextField persMobileNum = new JTextField(20);
protected JTextField homeNum = new JTextField(20);
protected JTextField compagnyNum= new JTextField(20);
protected JTextField profMobileNum = new JTextField(20);
protected JTextField email = new JTextField(20);
protected JButton photo = new JButton("Click to search photo");
protected JComboBox groups = new JComboBox();
protected JTextField website = new JTextField(20);

protected JPanel p = new JPanel();

public FormModify(){
        super();
        build();//On initialise notre fenêtre
    }

public void build(){
                setTitle("Modify contact"); //On donne un titre à l'application
		setSize(400,400); //On donne une taille à notre fenêtre
		setLocationRelativeTo(null); //On centre la fenêtre sur l'écran
		setResizable(false); //On interdit la redimensionnement de la fenêtre
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //On dit à l'application de se fermer lors du clic sur la croix
                p.setLayout(new GridLayout(0,2));
                
                JLabel lblNom = new JLabel("Name", JLabel.LEFT);
                lblNom.setLabelFor(name);       // Définir le composant qui es labelé
                JLabel lblFirstName = new JLabel("Firstname", JLabel.LEFT);
                lblNom.setLabelFor(firstname);
                JLabel lblHomeAddress = new JLabel("Home address", JLabel.LEFT);
                lblNom.setLabelFor(homeAddress);
                JLabel lblCompagnyAddress = new JLabel("Compagny address", JLabel.LEFT);
                lblNom.setLabelFor(compagnyAddress);
                JLabel lblPersMobileNum = new JLabel("Personal mobile", JLabel.LEFT);
                lblNom.setLabelFor(persMobileNum);
                JLabel lblHomeNum = new JLabel("Home telephone", JLabel.LEFT);
                lblNom.setLabelFor(homeNum);
                JLabel lblCompagnyNum = new JLabel("Compagny telephone", JLabel.LEFT);
                lblNom.setLabelFor(compagnyNum);
                JLabel lblProfMobileNum = new JLabel("Professional number", JLabel.LEFT);
                lblNom.setLabelFor(profMobileNum);
                JLabel lblEmail = new JLabel("Email", JLabel.LEFT);
                lblNom.setLabelFor(email);
                JLabel lblPhoto = new JLabel("Photo", JLabel.LEFT);
                lblNom.setLabelFor(photo);
                JLabel lblOther = new JLabel("Group", JLabel.LEFT);
                lblNom.setLabelFor(groups);
                JLabel lblWebsite = new JLabel("Website", JLabel.LEFT);
                lblNom.setLabelFor(website);
                
                groups.addItem("famille");
                groups.addItem("amis");
                groups.addItem("collègues");
                p.add(lblNom);
                p.add(name);
                p.add(lblFirstName);
                p.add(firstname);
                p.add(lblHomeAddress);
                p.add(homeAddress);
                p.add(lblCompagnyAddress);
                p.add(compagnyAddress);
                p.add(lblPersMobileNum);
                p.add(persMobileNum);
                p.add(lblHomeNum);
                p.add(homeNum);
                p.add(lblCompagnyNum);
                p.add(compagnyNum);
                p.add(lblProfMobileNum);
                p.add(profMobileNum);
                p.add(lblEmail);
                p.add(email);
                p.add(lblPhoto);
                p.add(photo);
                p.add(lblOther);
                p.add(groups);
                p.add(lblWebsite);
                p.add(website);
                p.add(modify);
                
                this.setContentPane(p);
}

public void setFields(String name,String firstname,String homeAddress,String compagnyAddress,String persMobileNum,String homeNum,String officeNum,String profMobileNum,String email,String photo,String other,String website){
    this.name.setText(name);
    this.firstname.setText(firstname);
    if(homeAddress.equals(" ")){
        this.homeAddress.setText("");
    }else{
    this.homeAddress.setText(homeAddress);
    }
    if(compagnyAddress.equals(" ")){
        this.compagnyAddress.setText("");
    }else{
    this.compagnyAddress.setText(compagnyAddress);
    }
    if(persMobileNum.equals(" ")){
        this.persMobileNum.setText("");
    }else{
    this.persMobileNum.setText(persMobileNum);
    }
    if(homeNum.equals(" ")){
        this.homeNum.setText("");
    }else{
    this.homeNum.setText(homeNum);
    }
    if(officeNum.equals(" ")){
        this.compagnyNum.setText("");
    }else{
    this.compagnyNum.setText(officeNum);
    }
    if(profMobileNum.equals(" ")){
        this.profMobileNum.setText("");
    }else{
    this.profMobileNum.setText(profMobileNum);
    }
    if(email.equals(" ")){
        this.email.setText("");
    }else{
    this.email.setText(email);
    }
    this.photo.setText(photo);
    this.groups.setSelectedItem(other);
    if(website.equals(" ")){
        this.website.setText("");
    }else{
    this.website.setText(website);
    }
    this.setVisible(true);
}

public ArrayList getFields(){
    ArrayList modif = new ArrayList();
    if(this.name.getText().toString().equalsIgnoreCase("")){
        this.name.setText(" ");
        modif.add(this.name.getText());
    }else{
        modif.add(this.name.getText());
    }
    if(this.firstname.getText().toString().equalsIgnoreCase("")){
        this.firstname.setText(" ");
        modif.add(this.firstname.getText());
    }else{
        modif.add(this.firstname.getText());
    }
    if(this.homeAddress.getText().toString().equalsIgnoreCase("")){
        this.homeAddress.setText(" ");
        modif.add(this.homeAddress.getText());
    }else{
    modif.add(this.homeAddress.getText());
    }
    if(this.compagnyAddress.getText().toString().equalsIgnoreCase("")){
        this.compagnyAddress.setText(" ");
        modif.add(this.compagnyAddress.getText());
    }else{
    modif.add(this.compagnyAddress.getText());
    }
    if(this.persMobileNum.getText().toString().equalsIgnoreCase("")){
        this.persMobileNum.setText(" ");
        modif.add(this.persMobileNum.getText());
    }else{
    modif.add(this.persMobileNum.getText());
    }
    if(this.homeNum.getText().toString().equalsIgnoreCase("")){
        this.homeNum.setText(" ");
        modif.add(this.homeNum.getText());
    }else{
    modif.add(this.homeNum.getText());
    }
    if(this.compagnyNum.getText().toString().equalsIgnoreCase("")){
        this.compagnyNum.setText(" ");
        modif.add(this.compagnyNum.getText());
    }else{
    modif.add(this.compagnyNum.getText());
    }
    if(this.profMobileNum.getText().toString().equalsIgnoreCase("")){
        this.profMobileNum.setText(" ");
        modif.add(this.profMobileNum.getText());
    }else{
    modif.add(this.profMobileNum.getText());
    }
    if(this.email.getText().toString().equalsIgnoreCase("")){
        this.email.setText(" ");
        modif.add(this.email.getText());
    }else{
    modif.add(this.email.getText());
    }
    modif.add(this.photo.getText());
    modif.add(this.groups.getSelectedItem());
    if(this.website.getText().toString().equalsIgnoreCase("")){
        this.website.setText(" ");
        modif.add(this.website.getText());
    }else{
    modif.add(this.website.getText());
    }
    return modif;
}
public void modified(ActionListener listener){
    modify.addActionListener(listener);
}
}
